import { Button } from 'antd';

import { renderOverflowText, getSorter } from '../common/Format';

import { SchemaManageAPI } from '@/components/SchemaComponent/SchemaManage/type';
import { PlusOutlined, EyeOutlined } from '@ant-design/icons';

/**
 * @getSourceBidderManageTableColumns
 * @description 寻源中标公告管理数据表格信息展示和操作
 */
const getSourceBidderManageTableColumns = (operation: any): Record<string, any>[] => {
  const { onView } = operation;
  return [
    {
      title: '中标标题',
      dataIndex: 'noticeTitle',
      key: 'noticeTitle',
      visible: true,
      width: 180,
      fixed: 'left',
      sorter: (a: any, b: any) => getSorter(a?.noticeTitle, b?.noticeTitle),
      render: (text: string) => renderOverflowText(text, true),
    },
    {
      title: '中标内容',
      dataIndex: 'noticeInfo',
      key: 'noticeInfo',
      visible: true,
      sorter: (a: any, b: any) => getSorter(a?.planInfo, b?.planInfo),
      width: 200,
      render: (text: string) => renderOverflowText(text),
    },
    {
      title: '中标时间',
      dataIndex: 'bidTime',
      key: 'bidTime',
      visible: true,
      sorter: (a: any, b: any) => getSorter(a?.bidTime, b?.bidTime),
      width: 180,
      render: (text: string) => renderOverflowText(text),
    },
    {
      title: '中标金额',
      dataIndex: 'factSum',
      key: 'factSum',
      visible: true,
      sorter: (a: any, b: any) => getSorter(a?.factSum, b?.factSum),
      width: 120,
      render: (text: string) => renderOverflowText(text),
    },
    {
      title: '公示开始时间',
      dataIndex: 'startTime',
      key: 'startTime',
      sorter: (a: any, b: any) => getSorter(a?.startTime, b?.startTime),
      visible: true,
      width: 180,
    },
    {
      title: '公示结束时间',
      dataIndex: 'endTime',
      key: 'endTime',
      visible: true,
      sorter: (a: any, b: any) => getSorter(a?.endTime, b?.endTime),
      width: 180,
    },
    {
      title: '采购结果确认',
      dataIndex: 'attachURL',
      sorter: (a: any, b: any) => getSorter(a?.attachURL, b?.attachURL),
      visible: false,
      width: 150,
      render: (text: string) => renderOverflowText(text),
    },
    {
      title: '操作',
      dataIndex: 'operation',
      key: 'operation',
      width: 180,
      visible: true,
      unDrag: true,
      align: 'left',
      fixed: 'right',
      render: (_: string, record: Record<string, any>) => {
        return (
          <Button
            type={'link'}
            size={'small'}
            className="manageBtntTxtStyle"
            icon={<EyeOutlined />}
            onClick={() => {
              onView(record);
            }}
          >
            查看
          </Button>
        );
      },
    },
  ];
};

/**
 * @getSourceBidderManageTableHeaderActions
 * @description 寻源中标公告管理表格顶部自定义按钮
 * @returns SchemaManageAPI.IActionBtnList[]
 */
const getSourceBidderManageTableHeaderActions = (operation: any): SchemaManageAPI.IActionBtnList[] => {
  const { onAdd } = operation;
  return [
    {
      title: '添加',
      visible: true,
      type: 'primary',
      icon: <PlusOutlined />,
      onClick: () => {
        onAdd();
      },
    },
  ];
};
export { getSourceBidderManageTableColumns, getSourceBidderManageTableHeaderActions };
